using System;
using System.Data.Entity;

namespace MvcApplication1.Models
{
    public class BreezeSampleDatabaseInitializer :
        // If you prefer to preserve the database between server sessions
        // inherit from DropCreateDatabaseIfModelChanges
        //DropCreateDatabaseIfModelChanges<BreezeSampleContext>

        // When creating the database the first time or 
        // if you prefer to recreate with every new server session
        // inherit from DropCreateDatabaseAlways 
        DropCreateDatabaseAlways<BreezeSampleContext>
    {
        protected override void Seed(BreezeSampleContext context){
            var grandchild = new[]{
                new GrandChild{gId = 1, Client = "House"},
                new GrandChild{gId = 2, Client = "Home"}
            };

            var child = new[]
                {
                    new BreezeSampleChildItem{Id = 1, Host = "H1", GrandChilds = grandchild},
                    new BreezeSampleChildItem{Id = 2, Host = "H2"}
                };

            var child2 = new[]
                {
                    new BreezeSampleChildItem{Id = 3, Host = "H3"}
                };


            var todo = new[]{
                new BreezeSampleTodoItem{Id = 1, Question = "E1" , BreezeSampleChildItems = child},
                new BreezeSampleTodoItem{Id = 2, Question = "E2" , BreezeSampleChildItems = child2}
            };

            Array.ForEach(child, t => context.BreezeSampleChildItems.Add(t));
            Array.ForEach(child2, t => context.BreezeSampleChildItems.Add(t));

            Array.ForEach(todo, t => context.BreezeSampleTodoItems.Add(t));
            context.SaveChanges(); // Save 'em
        }
    }
}
